package com.ruoyi.blog.mapper;

import com.ruoyi.blog.domain.BlogCategory;
import com.ruoyi.blog.domain.vo.BlogCategoryVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 博客分类Mapper接口
 *
 * @author ruoyi
 * @date 2023-10-02
 */
public interface BlogCategoryMapper extends BaseMapperPlus<BlogCategoryMapper, BlogCategory, BlogCategoryVo> {

    @Select("select category_id from ( " +
        " select " +
        " t1.category_id, " +
        " if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', category_id), 0) as ischild\n" +
        " from ( " +
        " select " +
        " category_id, " +
        " parent_id " +
        " from blog_category t order by parent_id, category_id " +
        " ) t1, " +
        " (select @pids := #{categoryId}) t2 " +
        ") t3 where ischild != 0 OR category_id = #{categoryId}")
    List<Long> getAllIdByParent(Long categoryId);
}
